package com.kylin.shared.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author Damon S.
 * @version v1.0.1
 * @date 2021年01月24日 14:16
 */
@Getter
@RequiredArgsConstructor
public enum RefundState implements Serializable {

    /** 营销类型：未知，退款中，成功，失败 */
    NA(0, "未知"),
    REFUNDING(1, "退款中"),
    SUCCEED(2, "成功"),
    FAILED(3, "失败");

    private final int code;
    private final String name;

    /**根据传值转换枚举值**/
    public static RefundState parse(int code) {
        List<RefundState> filtered =
                Arrays.stream(RefundState.values())
                        .filter(v -> Objects.equals(v.getCode(), code))
                        .collect(Collectors.toList());
        return CollectionUtils.isEmpty(filtered) ? NA : filtered.get(0);
    }
}
